<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>会议编辑</title>
<link rel="stylesheet" href="../../css/ecp.min.css" />
<link rel="stylesheet" href="../../css/picUpload.css" />
<script src="../../js/lib.min.js"></script>
<script src="../../js/requirejsConfigObj.js"></script>
<script src="../../js/requirejs/2.1.17.js"></script>
<script src="../../js/datepicker/4.8.b2/WdatePicker.js"></script>
<script src="../../js/common.min.js"></script>

<style  type="text/css">
    .check_error{color:red;border-color:red;}
    .width130{width:460px;height: 25px;}
    .errText{margin-left:10px;visibility:hidden; }
   
</style>    
</head>
<body> 
  <div id="showMsg" class="project"></div> 
  <div class="project-dialog"> 
   <form id="formItem" name="formItem" style="width: 100%;"> 
     <div>
      <table class="form_table" width="95%"> 
       <tbody id="table_tbody">
       <tr>
            <td width="130">
                 <label class="description"> <span class="fn-high">*</span>会议标题</label>
            </td>
            <td width="260" colspan="3">
                <input type="text" class="inputWidth width130" maxlength="100" name="meetNm" id="meetNm"/>                   
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> <span class="fn-high">*</span>会议类型</label>
            </td>
            <td width="260" colspan="3">
                <select class="inputSelect inputWidth" id="meetTypeCd" name="meetTypeCd">
					<option value="">--请选择--</option>
					<option value="1001">招商会</option>
					<option value="1002">禅修辟谷</option>
					<option value="1003">回春功</option>
					<option value="1004">加盟商培训</option>
					<option value="1005">其他</option>
				 </select>                        
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> 会议时间</label>
            </td>
            <td width="260" colspan="3">                
                <input type="text" id="meetBgnTime" name="meetBgnTime" class="ui-FormInputText Wdate inputText" value="" onFocus="WdatePicker({
				    onpicked:function(){meetEndTime.focus();},
				    startDate:'%y-%M-%d',
				    realDateFmt:'yyyy-MM-dd',
				    dateFmt:'yyyy-MM-dd',
				    maxDate:'#F{$dp.$D(\'meetEndTime\')}'
				    })" /> -
				<input type="text" id="meetEndTime" name="meetEndTime" class="ui-FormInputText Wdate inputText" value="" onFocus="WdatePicker({
				  startDate:'%y-%M-%d',
				  realDateFmt:'yyyy-MM-dd',
				  dateFmt:'yyyy-MM-dd',
				  minDate:'#F{$dp.$D(\'meetBgnTime\')}',
				  })" />          
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> 会议地址</label>
            </td>
            <td width="260" colspan="3">
            	<input type="text" class="inputWidth width130" maxlength="100" name="meetAddr" id="meetAddr"/>      
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> 会议人数</label>
            </td>
            <td width="260" colspan="3">
            	<input type="text" class="inputWidth width130" maxlength="100" name="meetPeopleNum" id="meetPeopleNum"/>      
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> 负责人</label>
            </td>
            <td width="260" colspan="3">
            	<input type="text" class="inputWidth width130" maxlength="100" name="meetPersn" id="meetPersn"/>      
            </td>            
        </tr>
        <tr>
            <td width="130">
                 <label class="description"> 联系电话1</label>
            </td>
            <td width="260" colspan="3">
            	<input type="text" class="inputWidth width130" maxlength="100" name="consultTelnum" id="consultTelnum" onblur="checkTel(this);"/>      
            </td>            
        </tr>
        <tr>
            <td width="130">
                 <label class="description"> 联系电话2</label>
            </td>
            <td width="260" colspan="3">
            	<input type="text" class="inputWidth width130" maxlength="100" name="consultTelnum2" id="consultTelnum2" onblur="checkTel(this);"/>      
            </td>            
        </tr>
        <tr>
           <td>
               <label class="description"> <span class="fn-high">*</span>会议简介</label>
           </td>
           <td colspan="3">
               <textarea type="text" name="meetDesc" id="meetDesc" class="form-textarea"  placeholder="请输入2000字以内" style="width: 700px;height: 130px;" resize:none ;onblur="true" maxlength="500"></textarea>
           </td>
       </tr>
       <tr>
	        <td>
	            <label class="description"> <span class="fn-high">*</span>会议介绍</label>
	        </td>
	        <td>
	            <textarea type="text" name="meetCntt" id=meetCntt style="width:650px;height:400px;visibility:hidden;"></textarea>
	        </td>
       </tr>       
       </tbody> 
      </table> 
      <hr />
     <div class="formBtnArea"> 
      <table width="100%"> 
       <tbody>
        <tr> 
         <td> 
          <div class="normalBtnArea fn-center"> 
           <input type="hidden" id="meetId" name="meetId" value=""/>
           <a class="normalBtn BGblue largeBtn" href="javascript:;" id="J_save" attr_save_type="1" onclick="save()">保存</a> 
           <a href="javascript:;" class="BGblue largeBtn" id="J_cancel" onclick="cancleConfirm()"><span>返回</span></a> 
          </div> 
          </td> 
        </tr> 
       </tbody>
      </table> 
     </div> 
    </div> 
   </form> 
  </div>
 </body>

<script src="../../js/kindeditor/kindeditor.js"></script>
<script src="../../js/self_fun.js"></script>
<script type="text/javascript">

$(function(){
	//qryOpAndRaVal();
	editor = KindEditor.create('textarea[name="meetCntt"]', {
        allowFileManager: true,
        uploadJson: "../../front/sh/care!uploadPicImg?uid=p002&type=rich",
        items: [
          'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
          'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
          'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
          'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
          'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
          'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
          'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
          'anchor', 'link', 'unlink', '|', 'about'
        ]
      });
	var meetId = getUrlParam("meetId");
	$("#meetId").val(meetId);
	getMeetDtl(meetId);
});
function getMeetDtl(meetId){
	editor.html('');
	var param = {'meetId':meetId};   
	 Util.ajax.postJsonSync('/getMeetLDtlInfo', param, function(json,status){
        var obj = json.bean;
        if(status){
       	 	$("#meetNm").val(obj.meetNm);
            $("#meetTypeCd").val(obj.meetTypeCd);
            editor.html(obj.meetCntt);
            $("#meetDesc").val(obj.meetDesc);            
            $("#meetBgnTime").val(obj.meetBgnTime);
            $("#meetEndTime").val(obj.meetEndTime);            
            $("#meetAddr").val(obj.meetAddr);
            $("#meetDay").val(obj.meetDay);
            $("#meetPeopleNum").val(obj.meetPeopleNum);
            $("#signUpPrsnnum").val(obj.signUpPrsnnum);
            $("#meetPersn").val(obj.meetPersn);
            $("#consultTelnum").val(obj.consultTelnum);
            $("#consultTelnum2").val(obj.consultTelnum2);
        }else{
            Util.dialog.tips("查询失败,请重试");
        }
	 });
}
function  qryOpAndRaVal(){
    var str = "5000$5023";
    var param={queryType:str};
    Util.ajax.postJsonSync("/home", param, function(json,status){
              alert(json.aaaa);           
    });
}
function checkTel(_this){
	var str = $(_this).val();
	if(!isDataNull(str)){
		if(!checkTelnum(str)){
			 Util.dialog.tips("请正确填写电话格式");
		}
	}
}
function save(){  
	var meetNm = $("#meetNm").val();
   	if(isDataNull(meetNm)){
   		top.Util.dialog.tips('请填写会议标题！');
   	 return;
   	}
   	var meetPersn = $("#meetPersn").val();
   	if(isDataNull(meetPersn)){
   		top.Util.dialog.tips('请填写负责人！');
   	 return;
   	}
   	var consultTelnum = $("#consultTelnum").val();
   	if(isDataNull(consultTelnum)){
   		top.Util.dialog.tips('请填写联系电话1！');
   	 return;
   	}
   	var meetDesc = $("#meetDesc").val();
   	if(isDataNull(meetDesc)){
   		top.Util.dialog.tips('请填写会议简介！');
   	 return;
   	}   	
	var ntcCnttContent = "";
   	ntcCnttContent = editor.html();
   	if(ntcCnttContent=='' ||ntcCnttContent==null){
    	 top.Util.dialog.tips('请填写会议介绍！');
    	 return;
    } 
   	var meetTypeCd = $("#meetTypeCd").val();
   	var meetPeopleNum = $("#meetPeopleNum").val();
   	var meetEndTime = $("#meetEndTime").val();
   	var meetBgnTime = $("#meetBgnTime").val();
   	var meetAddr = $("#meetAddr").val();
   	var consultTelnum2 = $("#consultTelnum2").val();
   	var meetId = $("#meetId").val();
   	var param = {
   			'meetNm':meetNm,
   			'meetId':meetId,
   			'meetPersn':meetPersn,
   			'meetTypeCd':meetTypeCd,
   			'meetDesc':meetDesc,
   			'meetPeopleNum':meetPeopleNum,
   			'meetEndTime':meetEndTime,
   			'meetBgnTime':meetBgnTime,
   			'meetAddr':meetAddr,
   			'meetCntt':ntcCnttContent,
   			'consultTelnum':consultTelnum,
   			'consultTelnum2':consultTelnum2
   	};
	Util.ajax.postJsonSync("/updateMeetInfo",param,function(json,status){
           if(status){
        	   if(json.bean.rtnCd == "00"){
                   window.parent.inint();
                   window.parent.closeIframeDialog();
               }else{              
                   window.parent.setTip("保存失败",top,2000);
               }
           }else{
               Util.dialog.tips("保存失败,请重试!!");
           }
     }); 
}
	//取消确认弹框
	function cancleConfirm(){
		//window.location.href = "newProjEstabMana.html?";
		window.parent.closeIframeDialog();
	};
	
    function isDataNull(str) {
        if (str == null || str == "" || str == undefined || str == '[]') {
            return true;
        }
        return false;
    }
	
  
    //表单校验
    var validatePoorHouseInfo = $("#formItem").validate({
    	rules:{
    		meetNm:{
        		required:true,
        	},
        	meetTypeCd:{
        		required:true,
        	},
        	meetDesc:{
        		required:true,
            }
        },
        messages:{
        	meetNm:{
        		required:"必填",
            },
            meetTypeCd:{
            	required:"必填",
            },
            meetDesc:{
            	required:"必填",
            }
        },
        showErrors:function(){
            this.defaultShowErrors();
        }
    });
    jQuery.validator.addMethod("checkNumber",function(value,element) { 
        var regUrl = /^[1-9]\d{0,14}$/;// /^\d{0,15}$/;
        return this.optional(element) || regUrl.test(value);
    }, "请输入正整数");
    
    jQuery.validator.addMethod("checkLittleNumber",function(value,element) { 
    	var regUrl = /^\d{0,10}(\.\d{1,4})?$/;
        return this.optional(element) || regUrl.test(value);
    }, "保留4位小数");
    
    function checkNumberDecimals(num){
    	var regx = /^\d{0,20}(\.\d{1,2})?$/;
    	if(regx.test(num)){
    		return true;
    	}else{
    		return false;
    	}
    }
  	//账号校验  请正确填写银行账号
    function checkAcctNum(num){
    	var regUrl = /^\+?[1-9][0-9]*$/;
   	  	if(regUrl.test(num) && num.length >= 14 && num.length <= 19){
   		  	return true;
   	  	}else{
   		  	return false;
   	  	}
    }
    function checkTotalInvest(num){
    	var regx = /^\d{0,7}(\.\d{1,4})?$/;
    	if(regx.test(num)){
    		return true;
    	}else{
    		return false;
    	}
    }
    function checkTotalNum(num){
    	var regx = /^\d+$/;
    	if(regx.test(num)){
    		return true;
    	}else{
    		return false;
    	}
    } 
 
  //项目备案材料上传初始化方法
  function initWebS1(fileId,pickerId,picPaths){
	  var $ = jQuery,
     $list = $(fileId),
	// 优化retina, 在retina下这个值是2
	      ratio = window.devicePixelRatio || 1,
	
	// 缩略图大小
	      thumbnailWidth = 100 * ratio,
	      thumbnailHeight = 100 * ratio,
	// Web Uploader实例
	 uploader;
	 var familyPicUrls = '';
	 var allPicUrls = '';//包含所有前端页面预览过的图片的地址
	// 初始化Web Uploader
	uploader = WebUploader.create({
	  // 自动上传。
	  auto: true,
	
	  // 图片上传前进行压缩
	  compress: false,
	  duplicate :true,  
	  // swf文件路径
	  swf:  '../../asset/lib/webuploader/Uploader.swf',
	  //server:'../../front/sh/info!fanxianUploadPicImg?uid=s001',
	  server:'../../front/sh/info!fanxianUploadPicImg?uid=s001',
	  // 选择文件的按钮。可选。
	  // 内部根据当前运行是创建，可能是input元素，也可能是flash.
	  pick: {id:pickerId,multiple:true},
	  // 只允许选择文件，可选。
	  accept: {
	      title: 'Images',
	      extensions: 'gif,jpg,jpeg,bmp,png',
	      mimeTypes: 'image/jpg,image/jpeg,image/png,image/bmp,image/gif'
	  },
	   fileVal: "file",
	   fileSingleSizeLimit:3145728
	});
	
	         
	//图片加入队列前,判断图片大小
	uploader.on('beforeFileQueued',function(file){
	    var picUpload = $(fileId).find(".file-item");
	    if(picUpload.length >= 10){
	      Util.dialog.tips("最多只能上传10张照片",top,1000);
	      return false;
	    }  
	    if(file.size > 3145728){
	        Util.dialog.tips("图片大于3M，请重新选择",top,1000);
	    }
	    var injStra = ["script", "mid", "master", "truncate ", "insert ", "select ",
                       "delete ", "update ", "declare", "iframe", "onreadystatechange", "alert", "atestu", "xss",
                       ";","'","\"","<",">","(",")",",","\\","svg","confirm","prompt","onload","onmouseover",
                       "onfocus","onerror","and ","or ","union ","where ","limit ","group ","by ","hex","substr",
                       "\r","\n"];
        var injFileName = file.name.toLowerCase();
        var flag = 1;
        for (var i = 0; i<injStra.length; i++) {
            if (injFileName.indexOf(injStra[i])>=0) {              
                flag =2;
            }
        }
        if(flag == 2){
            Util.dialog.tips("图片名称含有特殊字符，请修改");                
            return false;
        }
	    window.parent.setIframeHeight();
	})
	uploader.on( 'uploadStart', function( file ) {});
	// 当有文件添加进来的时候
	uploader.on( 'fileQueued', function( file ) {  
	  var $li = $(
	          '<div id="' + file.id + '" class="file-item thumbnail">' +
	          '<img>' +
	          '<div class="delpic"><span id=""  style="color: #08c;visibility:hidden;">删除图片</span></div><div class="excelProcess" style="visibility:hidden;"></div></div>'
	  ),
	  $img = $li.find('img');
	  $list.append( $li );    
	  $("J_save").css('visibility','hidden');         
	$(".delpic").find('span').on('click',function(){
	      var _this=$(this);
	      var picId=_this.attr("id");//在图片上传时已修改为图片地址
	      var picUrls = $(picPaths).val();  
	      var regx = new RegExp('\\$?'+picId);
	      var path = picUrls.replace(regx, "");
	      if(path.indexOf('$') === 0){path = path.substring(1);}
	      $(picPaths).val(path);
	      _this.parents(".file-item").remove();
	      window.parent.setIframeHeight();
	});
	// 创建缩略图
	uploader.makeThumb( file, function( error, src ) {
	  if ( error ) {
	      $img.replaceWith('<span>不能预览</span>');
	      return;
	  }   
	  $img.attr( 'src', src );
	}, 60, 60 );
	window.parent.setIframeHeight();
	});
	
	// 文件上传过程中创建进度条实时显示。
	uploader.on( 'uploadProgress', function( file, percentage ) {
	  $('#'+file.id).find('.excelProcess').css('visibility','visible');
	  $('#'+file.id).find('.excelProcess').html('<p class="progress" style="width:'+percentage * 99+'%"></p><span>'+(percentage.toFixed(2)* 99)+'%</span>');
	  window.parent.setIframeHeight();
	});
	// 文件上传成功，给item添加成功class, 用样式标记上传成功。
	uploader.on( 'uploadSuccess', function(file, data) {
	  var picUrl = data.bean.picUrl+"@"+file.name;
	  var imgName = data.bean.fileName;
	  familyPicUrls = $(picPaths).val();
	  familyPicUrls += "$"+picUrl;
	  if(familyPicUrls.indexOf('$') === 0){familyPicUrls = familyPicUrls.substring(1);}
	  $('#' + file.id).find(".delpic span").attr("id", picUrl);
	  $(picPaths).val(familyPicUrls);//最终上传图片
	  $( '#'+file.id ).addClass('upload-state-done');
	  $('#'+file.id).find('.excelProcess').css('visibility','visible');
	  $('#'+file.id).find('.excelProcess').html('上传成功');
	  $('#'+file.id).find(".delpic span").css('visibility','visible');
	 
	  window.parent.setIframeHeight();
	});
	// 文件上传失败，显示上传出错。
	uploader.on( 'uploadError', function( file ) {
	  var $li = $( '#'+file.id ),
	          $error = $li.find('div.error');
	  if ( !$error.length ) {
	      $error = $('<div class="error"></div>').appendTo( $li );
	  }
	  if(uploader.getFiles('queued','progress').length == 0){
		  $("J_save").css('visibility','visible');
	  }
	  $("#"+file.id).remove();
	});
	
	// 完成上传完了，成功或者失败，先删除进度条。
	uploader.on( 'uploadComplete', function( file ) {
	
	});
	
	//解决ie9下上传png无法到后台的问题
	if(navigator.userAgent.indexOf("MSIE")>0 && navigator.userAgent.indexOf("MSIE 9.0")>0){   
	var setHeader = function(object, data, headers) {
	      headers['Access-Control-Allow-Origin'] = '*';
	      headers['Access-Control-Request-Headers'] = 'content-type';
	      headers['Access-Control-Request-Method'] = 'POST';
	  }
	uploader.on('uploadBeforeSend ', setHeader);
	}
  }

  function zTreeOnClick(event, treeId, treeNode) {
	    if(treeNode.regnCode.substring(9) != '000'){
	    	return;
	    }
		Util.ajax.postJsonSync(srvMap.get('queryRegnOptions'),{regnCode:treeNode.regnCode}, function(json, status) {
			if (status) {
				var treeObj = $.fn.zTree.getZTreeObj("J_zTree");
				var newNodes = json.beans;
				newNodes = treeObj.addNodes(treeNode, newNodes);
			}
		});
	
	}
	var setting = {
		view: {
			selectedMulti: true
		},
		check: {
			enable: true,
			chkStyle: "checkbox",
			chkboxType:{ "Y" : "s", "N" : "s" }
		},
		data: {
			simpleData: {
				enable: true,
				idKey: "regnCode",
				pIdKey: "suprRegnCode",
				rootPId: -1
			},
			key: {
				name: "regnNm"
			}
		},
		callback: {
			onClick: zTreeOnClick
		}
	};
  var initTree = function() {
		var regnCode = $("#cntyCode").val();
		Util.ajax.postJson(srvMap.get('queryRegnOptions'),{'regnCode':regnCode}, function(json, status) {
			if (status) {
				$.fn.zTree.init($("#J_zTree"), setting, json.beans);
				var str = $("#projImplAddr").val();
				if(!isDataNull(str)){
					 showZtree(str);
				}
			}
		});
	}
  function showZtree(arr){
	  if(isDataNull(arr)){
		  return;
	  }
	    var treeObj = $.fn.zTree.getZTreeObj("J_zTree"); 
		var nodes=treeObj.getNodes();
		var obj=treeObj.transformToArray(nodes);
		var regnStrTown = arr.split(",").map(function(x){return x.substring(0,9)+"000"});
		var regnStrAdmin = arr.split(",");
		regnStrTown.map(function(x){
			treeObj.setting.callback.onClick(null, treeObj.setting.treeId, 
					treeObj.getNodeByParam("regnCode",x,null));
		});
		regnStrAdmin.map(function(x){
			treeObj.checkNode(treeObj.getNodeByParam("regnCode",x,null))
		});
	}

//校验投资金额
function projInputAmtCheck(){
	  var value = $("#projInputAmt").val();
	  var regUrl = /^[1-9]\d{0,14}(\.\d{1,4})?$/;
    if(!regUrl.test(value)){
  	  $("#projInputAmt").next().show();
    }else{
  	  $("#projInputAmt").next().hide();
    }
}
</script>
</body>
</html>